#include <bits/stdc++.h>
#include <string>
using namespace std;

bool haveVisit[26];

/** counts[i][j]：统计第i个字符在长度为j的过程中出现了几次 */
int counts[26][50] = {0};


// 返回长度为l，且每个元素都是c的字符串
string repeatStr(char c, int l)    // repeatStr('a',3)  -> "aaa"
{
	string str = "";
	for (int i = 1; i <= l; i++)
		str += c;
	return str;
}

int main()
{

	string str;
	cin >> str;
	int len = str.size();
	for (int i = 0; i < len; i++) // "abc"
	{
		char c = str[i];
		int char_int = (int)c - (int)('a');
		if(haveVisit[char_int]) continue;
		haveVisit[char_int] = true;
		for (int j = 1; j <= len; j++)// 'a' 'aa' 'aaa'
		{
			string s = repeatStr(c,j);
			for(int k=0;k<=len-j;k++){
			// s1.substr(i,j) // 字符串s1，在第i位截取长度为j的子串
	           if(str.substr(k,j)==s) counts[char_int][j]++;
			}
		}
	}
	int maxx = -1;
	for(int i=0;i<26;i++){
		int n = -1;
		for(int k=len;k>0;k--){
			if(counts[i][k]>=3){
				n = k;
				break;
			}
		}
		maxx = max(maxx,n);
	}
	cout << maxx;
	return 0;
}